home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-19 | 5.7 KB | 281 lines | [TEXT/KAHL] |
- // Prototypes
- void EventLoop( void );
- void HandleMouseDown( EventRecord myEvent );
- void HandleKeyPress( EventRecord myEvent );
- void HandleContents( Point clickPnt, WindowPtr theWindow );
- void HandleMenuChoice( long menuChoice );
- void AppleChoice( int theItem );
- void FileChoice( int theItem );
- void EditChoice( int theItem );
- void DoWindowUpdates( WindowPtr theWindow );
-
- // Globals
- extern MenuHandle gAppleMenu;
- extern Boolean gDone;
- extern Main myMain;
-
- /****************************************************************************
-
- Main Event Loop
-
- *****************************************************************************/
- void EventLoop( void )
- {
- EventRecord myEvent;
-
- if( WaitNextEvent( everyEvent, &myEvent, 30, 0 ))
- {
- switch( myEvent.what )
- {
- case mouseDown:
- HandleMouseDown( myEvent );
- break;
-
- case keyDown:
- case autoKey:
- HandleKeyPress( myEvent );
- break;
-
- case updateEvt:
- DoWindowUpdates( (WindowPtr)myEvent.message );
- break;
-
- case diskEvt:
- break;
-
- case activateEvt:
- break;
-
- case app4Evt:
- break;
-
- default:
- break;
- }
- }
- }
-
- /****************************************************************************
-
- Handle any MouseDown Events
-
- *****************************************************************************/
- void HandleMouseDown( EventRecord myEvent )
- {
- short thePart;
- WindowPtr whichWindow;
-
- thePart = FindWindow( myEvent.where, &whichWindow );
-
- switch( thePart )
- {
- case inSysWindow:
- SystemClick( &myEvent, whichWindow );
- break;
-
- case inMenuBar:
- HandleMenuChoice( MenuSelect( myEvent.where ));
- break;
-
- case inContent:
- SelectWindow( whichWindow );
- HandleContents( myEvent.where, whichWindow );
- break;
-
- case inDrag:
- DragWindow( whichWindow, myEvent.where, &qd.screenBits.bounds );
- break;
-
- case inGrow:
- break;
-
- case inGoAway:
- if( TrackGoAway( whichWindow, myEvent.where ) ) {
- gDone = TRUE;
- }
- break;
-
- case inZoomIn:
- break;
-
- case inZoomOut:
- break;
-
- default:
- break;
- }
- }
-
- /****************************************************************************
-
- Handle any KeyDown Events
-
- *****************************************************************************/
- void HandleKeyPress( EventRecord myEvent )
- {
- char key;
-
- key = myEvent.message & charCodeMask;
- if( myEvent.modifiers & cmdKey ) {
- if( myEvent.what == keyDown ) {
- HandleMenuChoice( MenuKey( key ));
- }
- }
- }
-
- /****************************************************************************
-
- Handle Contents if clicked in my window.
-
- *****************************************************************************/
- void HandleContents( Point clickPnt, WindowPtr whichWindow )
- {
- short partCode, iPartCode, whatWindow;
- ControlHandle theControl;
-
- whatWindow = GetWRefCon( whichWindow );
- GlobalToLocal( &clickPnt );
-
- switch( whatWindow )
- {
- case MAIN_WINDOW:
- partCode = FindControl( clickPnt, whichWindow, &theControl );
- if( partCode != 0 ) {
- iPartCode = TrackControl( theControl, clickPnt, 0 );
-
- }
- break;
- }
- }
-
- /****************************************************************************
-
- HandleMenuChoice
-
- *****************************************************************************/
- void HandleMenuChoice( long menuChoice )
- {
- short theMenu, theItem;
-
- if( menuChoice != 0 )
- {
-
- theMenu = HiWord( menuChoice );
- theItem = LoWord( menuChoice );
- switch( theMenu ) {
- case MENU_APPLE:
- AppleChoice( theItem );
- break;
-
- case MENU_FILE:
- FileChoice( theItem );
- break;
-
- case MENU_EDIT:
- EditChoice( theItem );
- break;
-
- //Add more case's to handle any additional menu's
- }
- }
- HiliteMenu( 0 );
- }
-
- /****************************************************************************
-
- User selects the 'Apple Menu'
-
- *****************************************************************************/
- void AppleChoice( int theItem )
- {
- Str255 accName;
- int accNumber;
- short itemNumber;
-
- switch( theItem )
- {
- //Declare any of your menus for Edit here.
- //Be Sure to update the "MenuDeclarations.h" file
-
- case APPLE_ABOUT:
- CreateMySplashWindow();
- break;
-
- default:
- GetItem( gAppleMenu, theItem, accName );
- accNumber = OpenDeskAcc( accName );
- break;
- }
- }
-
- /****************************************************************************
-
- User selects the 'File Menu'
-
- *****************************************************************************/
- void FileChoice( int theItem )
- {
- switch( theItem )
- {
- //Declare any of your menus for File here.
- //Be Sure to update the "MenuDeclarations.h" file
-
- case FILE_QUIT:
- gDone = TRUE;
- break;
- }
- }
-
- /****************************************************************************
-
- User selects the 'Edit Menu'
-
- *****************************************************************************/
- void EditChoice( int theItem )
- {
- switch( theItem )
- {
- //Declare any of your menus for Edit here.
- //Be Sure to update the "MenuDeclarations.h" file
-
- case EDIT_UNDO:
- break;
-
- case EDIT_CUT:
- break;
-
- case EDIT_COPY:
- break;
-
- case EDIT_PASTE:
- break;
-
- case EDIT_CLEAR:
- break;
-
- case EDIT_SELECTALL:
- break;
- }
- }
-
- /****************************************************************************
-
- Handles any window updates.
-
- *****************************************************************************/
- void DoWindowUpdates( WindowPtr theWindow )
- {
- GrafPtr savedPort;
-
- GetPort( &savedPort );
-
- if( GetWRefCon( theWindow ) == MAIN_WINDOW )
- {
- SetPort( myMain.window );
- BeginUpdate( myMain.window );
- UpdateMainWindow( myMain.window );
- EndUpdate( myMain.window );
- }
-
- SetPort( savedPort );
- }